<template>
  <div class="container">
    <el-form ref="form" :model="form" :rules="rules" size="medium" :disabled="loading" label-width="80px">
      <el-form-item label="账号" prop="username">
        <el-input v-model="form.username" placeholder="请输入手机号/邮箱"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="form.password" type="password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :loading="loading" @click="onLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: null,
        password: null,
      },
      loading: false,
      rules: {
        username: [
          {required: true, message: '请输入账号', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'change'}
        ],
      }
    }
  },
  created() {
  },
  methods: {
    onLogin() {
      this.$refs['form'].validate(result => {
        if (!result)
          return false
        this.loading = true
        setTimeout(() => {
          this.loading = false
          sessionStorage.setItem('token', '1')
          this.$router.replace({path: '/'})
        }, 1000)
      })
    }
  }
}
</script>

<style scoped>
.container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-color: #fff;
}
</style>
